
#include "momgr.h"
#include <QDir.h>
#include <QDesktopServices>

#define DIR_PLUGIN "//plugin//"
#define FILENAME_CONFIG "//config.xml"



MOMGR *MOMGR::pInstance = NULL;

MOMGR *MOMGR::Instance()
{
	if (pInstance == NULL)
	{
		pInstance = new MOMGR;
	}
	return pInstance;
}

MOMGR::MOMGR()
{
	Reload();
}

MOMGR::~MOMGR()
{
    Clear();

}


void MOMGR::Clear()
{

    MODATA_ITR itr = m_modata.begin();
    for (; itr != m_modata.end(); itr++)
    {
        itr->second.clear();
    }
    m_modata.clear();

}

bool MOMGR::BuildMoInfo(const QString &pluginName, const QString &file)
{
	std::vector<MO> tmp;
	m_modata[pluginName] = tmp;
    return true;
}

void MOMGR::Reload()
{
	Clear();
	
    const QDir dir(QDir::currentPath()+QString(DIR_PLUGIN));
    QFileInfoList entries = dir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot| QDir::NoSymLinks);
    foreach (QFileInfo entry, entries)
    {

		if (!entry.isDir())continue;
		if (!QFile::exists(entry.filePath() + QString(FILENAME_CONFIG)))continue;
			
		(void)BuildMoInfo(entry.baseName(), entry.filePath()+QString(FILENAME_CONFIG));
		
    }


}


